package com.hbnu.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Fundsflow;
import com.hbnu.system.service.FundsflowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fundsflow")
@Api(tags = "支出、到账经费模块")
public class FundsflowController {
    @Autowired
    FundsflowService fundsflowService;

    @ApiOperation("支出录入")
    @PostMapping("/addfundsout")
    public Rest<Boolean> Addfundsout(@RequestBody Fundsflow fundsflow){
        boolean add = fundsflowService.addFundsout(fundsflow);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("支出删除")
    @GetMapping("/Deletefundsout")
    public Rest<Boolean> Deletefundsout(String ID){
        boolean delete = fundsflowService.deleteFundsout(ID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("支出修改")
    @GetMapping("/Updatefundsout")
    public Rest<Boolean> Updatefundsout(Fundsflow fundsflow){
        boolean update = fundsflowService.updateFundsout(fundsflow);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("支出提交")
    @GetMapping("/ReCommitfundsout")
    public Rest<Boolean> ReCommitfundsout(String ID){
        boolean add = fundsflowService.ReCommitFundsout(ID);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("根据主键支出经费查询")
    @GetMapping("/GetfundsoutById")
    public Rest<Fundsflow> GetfundsoutById(String ID){
        Fundsflow fundsflow = fundsflowService.getFundsflow(ID);
        return Rest.success(fundsflow);
    }

    @ApiOperation("支出经费分页查询")
    @PostMapping ("/pagecondition")
    public Rest<CommonPage<Fundsflow>> fundsoutpageProjectCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Fundsflow> page = fundsflowService.pageCondition(searchTaskDTO);
        CommonPage<Fundsflow> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }
    @ApiOperation("经费支出校级通过")
    @GetMapping("/SchoolCheckfundsoutPass")
    public Rest<String> SchoolPassfundsout(String ID){
        Boolean b = fundsflowService.schoolCheckfundsoutPass(ID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("经费支出校级退回")
    @PostMapping("/SchoolCheckfundsoutBack")
    public Rest<String> SchoolBackfundsout(@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = fundsflowService.schoolCheckfundsoutBack(checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("用户获取与自己相关的经费支出分页")
    @PostMapping("/UserGetRelatefundsout")
    public Rest<CommonPage<Fundsflow>> UserGetRelatefundsout(@RequestBody UserDTO userDTO){
        IPage<Fundsflow> fundsoutIPage = fundsflowService.userGetRelateFundsout(userDTO);
        CommonPage<Fundsflow> fundsoutCommonPage = CommonPage.restPage(fundsoutIPage);
        return Rest.success(fundsoutCommonPage);
    }
    @ApiOperation("校级管理员查看需要自己审核的支出分页")
    @PostMapping("/SchoolUserGetfundsout")
    public Rest<CommonPage<Fundsflow>> SchoolUserGetfundsout(@RequestBody UserDTO userDTO){
        IPage<Fundsflow> fundsoutIPage = fundsflowService.schoolUserGetfundsout(userDTO);
        CommonPage<Fundsflow> fundsoutCommonPage = CommonPage.restPage(fundsoutIPage);
        return Rest.success(fundsoutCommonPage);
    }
    @ApiOperation("校级管理员查看自己已经审核的支出分页")
    @PostMapping("/SchoolUserGetfundsoutOver")
    public Rest<CommonPage<Fundsflow>> SchoolUserGetfundsoutOver(@RequestBody UserDTO userDTO){
        IPage<Fundsflow> fundsoutIPage = fundsflowService.schoolUserGetfundsoutover(userDTO);
        CommonPage<Fundsflow> fundsoutCommonPage = CommonPage.restPage(fundsoutIPage);
        return Rest.success(fundsoutCommonPage);
    }
    @ApiOperation("到账录入")
    @PostMapping("/addfundsarrival")
    public Rest<Boolean> Addfundsarrival(@RequestBody Fundsflow fundsflow){
        boolean add = fundsflowService.addFundsarrival(fundsflow);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("到账删除")
    @GetMapping("/Deletefundsarrival")
    public Rest<Boolean> Deletefundsarrival(String ID){
        boolean delete = fundsflowService.deleteFundsarrival(ID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("到账修改")
    @GetMapping("/Updatefundsarrival")
    public Rest<Boolean> Updatefundsarrival(Fundsflow fundsflow){
        boolean update = fundsflowService.updateFundsarrival(fundsflow);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("到账提交")
    @GetMapping("/ReCommitfundsarrival")
    public Rest<Boolean> ReCommitfundsarrival(String ID){
        boolean add = fundsflowService.ReCommitFundsarrival(ID);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("根据主键到账经费查询")
    @GetMapping("/GetfundsarrivalById")
    public Rest<Fundsflow> GetfundsarrivalById(String ID){
        Fundsflow fundsflow = fundsflowService.getFundsarrivalflow(ID);
        return Rest.success(fundsflow);
    }

    @ApiOperation("到账经费分页查询")
    @PostMapping ("/pagearrivalcondition")
    public Rest<CommonPage<Fundsflow>> fundsarrivalpageProjectCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Fundsflow> page = fundsflowService.pageConditionarrival(searchTaskDTO);
        CommonPage<Fundsflow> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }
    @ApiOperation("经费到账校级通过")
    @GetMapping("/SchoolCheckfundsarrivalPass")
    public Rest<String> SchoolPassfundsarrival(String ID){
        Boolean b = fundsflowService.schoolCheckfundsarrivalPass(ID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("经费到账校级退回")
    @PostMapping("/SchoolCheckfundsarrivalBack")
    public Rest<String> SchoolBackfundsarrival(@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = fundsflowService.schoolCheckfundsarrivalBack(checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("用户获取与自己相关的经费到账分页")
    @PostMapping("/UserGetRelatefundsarrival")
    public Rest<CommonPage<Fundsflow>> UserGetRelatefundsarrival(@RequestBody UserDTO userDTO){
        IPage<Fundsflow> fundsoutIPage = fundsflowService.userGetRelateFundsarrival(userDTO);
        CommonPage<Fundsflow> fundsoutCommonPage = CommonPage.restPage(fundsoutIPage);
        return Rest.success(fundsoutCommonPage);
    }
    @ApiOperation("校级管理员查看需要自己审核的到账分页")
    @PostMapping("/SchoolUserGetfundsarrival")
    public Rest<CommonPage<Fundsflow>> SchoolUserGetfundsarrival(@RequestBody UserDTO userDTO){
        IPage<Fundsflow> fundsarrivalIPage = fundsflowService.schoolUserGetfundsarrival(userDTO);
        CommonPage<Fundsflow> fundsarrivalCommonPage = CommonPage.restPage(fundsarrivalIPage);
        return Rest.success(fundsarrivalCommonPage);
    }
    @ApiOperation("校级管理员查看自己已经审核的到账分页")
    @PostMapping("/SchoolUserGetfundsarrivalOver")
    public Rest<CommonPage<Fundsflow>> SchoolUserGetfundsarrivalOver(@RequestBody UserDTO userDTO){
        IPage<Fundsflow> fundsarrivalIPage = fundsflowService.schoolUserGetfundsarrivalover(userDTO);
        CommonPage<Fundsflow> fundsarrivalCommonPage = CommonPage.restPage(fundsarrivalIPage);
        return Rest.success(fundsarrivalCommonPage);
    }
}
